# import json
# import socket
#
# import requests
# from lxml import etree
# from tld import get_fld
#
# url = 'https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={}&resource_id=5809&format=json'
# record_url = 'https://icp.chinaz.com/{}'
# proxies = {"http": None, "https": None}
#
#
# class GetHost:
#     # 域名
#     domain = ''
#     # IP地址
#     ip = ''
#     # IP归属地
#     location = ''
#     # 主办单位名称
#     org_name = ''
#     # 主办单位性质
#     sponsor_nature = ''
#     # 网站名称
#     website_name = ''
#
#     def __init__(self, domain, ip):
#         self.domain = domain
#         self.ip = ip
#         self.get_host_info()
#
#     def get_host_info(self):
#         if self.ip == '':
#             self.ip = socket.gethostbyname(self.domain)
#         response = requests.get(url.format(self.ip), proxies=proxies)
#         json_obj = json.loads(response.text)
#         info = json_obj['data']
#         self.location = info[0]['location']
#         if self.domain != '':
#             response = requests.get(record_url.format(get_fld(self.domain, fix_protocol=True)),
#                                     proxies=proxies)
#             html = etree.HTML(response.content)
#             record_info = html.xpath('//li[@class=\'bg-gray clearfix\']')
#             self.org_name = record_info[0].xpath('./p/a/text()')[0]
#             record_info_1 = html.xpath('//li[@class=\'clearfix\']')
#             self.sponsor_nature = record_info_1[0].xpath('./p/strong/text()')[0]
#             self.website_name = record_info_1[1].xpath('./p/text()')[0]
#
#
# if __name__ == '__main__':
#     host = GetHost('www.qq.com', '')
#     print('域名：{}'.format(host.domain))
#     print('IP：{}'.format(host.ip))
#     print('归属地：{}'.format(host.location))
#     print('主办单位名称：{}'.format(host.org_name))
#     print('主办单位性质：{}'.format(host.sponsor_nature))
#     print('网站名称：{}'.format(host.website_name))
#
